package com.tuanzi.loan.web.bean.commuser;

import com.base.common.log.LogService;
import com.tuanzi.loan.business.entity.commuser.CommuserInfo;
import com.tuanzi.loan.business.service.commuser.CommuserInfoService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.commuser.CommuserInfosearchRequest;
import com.tuanzi.loan.vo.response.commuser.CommuserInfoSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.commuser.CommuserInfoLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import java.util.List;

/**
 * @Param
 * @author  xionghao
 * @create  2018.4.24
 * @describe 查询commuser bean
 **/
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class CommuserListBean extends JSFListingBean<CommuserInfosearchRequest,CommuserInfoSearchResponse>
        implements Serializable{

    private static final long serialVersionUID = 9141679811260925241L;
    public List<CommuserInfo> commuserinfolist;
    @Autowired
    private CommuserInfoService service;

    @PostConstruct
    private void init() {
        initLazyDataModel();
    }

    //延迟加载
    private void initLazyDataModel() {
        $ = new CommuserInfosearchRequest();
        lazyDataModel = new CommuserInfoLazyDataModel($);
    }

    public void returnInfoByMobnum(){
        if (StringUtils.isNotBlank($.getMobnum())){
            String mob = $.getMobnum();
            LogService.info($.toString());
            commuserinfolist=service.findCommuserBymobnum($);
            System.out.println(commuserinfolist);
        }
    }

    public void onReset(){
        initLazyDataModel();
    }

    //更换状态
    public void changeIsavaliable(Long id){
        service.saveOrUpdate(service.findOne(id));
        initLazyDataModel();
    }
    //对话框实现
    public void destroyWorld(Long id) {
        changeIsavaliable(id);
    }
}
